﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SQLite;
using System.Data;
using System.Windows;

using Geekola.ORM;

namespace phpBB
{
    public class DataBaseObjects
    {
        private SQLiteConnection sql_con;
        private SQLiteCommand sql_cmd;
        private SQLiteDataAdapter DB;
        private DataSet DS = new DataSet();
        private DataTable DT = new DataTable();
        private string _connString;

        

        private string columnValue = String.Empty;
        
        public DataBaseObjects(string ConnectionString)
        {
            _connString = ConnectionString;
        }
        public DataTable GetData(string queryString)
        {
            SetConnection();
            sql_con.Open();

            sql_cmd = sql_con.CreateCommand();
            string CommandText = queryString;
            DB = new SQLiteDataAdapter(CommandText, sql_con);
            DS.Reset();
            DB.Fill(DS);
            DT = DS.Tables[0];
            sql_con.Close();
            return DT;
        }
        private void SetConnection()
        {
            sql_con = new SQLiteConnection(_connString);
        }
        public void ExecuteQuery(string txtQuery)
        {
            SetConnection();
            sql_con.Open();

            sql_cmd = sql_con.CreateCommand();
            sql_cmd.CommandText = txtQuery;

            sql_cmd.ExecuteNonQuery();
            sql_con.Close();
        }
        private void Add()
        {


            string txtSQLQuery = "insert into  SITE (url) values ('" + columnValue + "')";
            ExecuteQuery(txtSQLQuery);

        }
        private void Delete(int id)
        {

            string txtSQLQuery = "delete from  SITE where id =" + id;

            ExecuteQuery(txtSQLQuery);

            columnValue = string.Empty;

        }
        private void Edit(int id)
        {

            string txtSQLQuery = "update  SITE set  url =\"" + columnValue + "\" where id =" + id;
            ExecuteQuery(txtSQLQuery);


        }
    }
}
